﻿using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;

namespace GameOnCopyBook.Sound
{

    public class SoundManager
    {
        private Song sInGame;
        private Song sInPause;
        private SoundEffect sShot;        
        private SoundEffect sDead;
        private SoundEffect sExplosion;
                        
        public void LoadContent(ContentManager content)
        {
            sInGame = content.Load<Song>(@"Audio\CourtesyLite");
            sInPause = content.Load<Song>(@"Audio\CourtesyMenu");
            sDead = content.Load<SoundEffect>(@"Audio\dead");
            sShot = content.Load<SoundEffect>(@"Audio\shot0");
            sExplosion = content.Load<SoundEffect>(@"Audio\explosion00");
                                    
        }

        public void PlayInGame()
        {
            MediaPlayer.Stop();
            MediaPlayer.Volume = 1.0f;
            
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(sInGame);
            
        }

        public void PlayInPause()
        {
            MediaPlayer.Stop();
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(sInPause);
        }

        public void StopMusic()
        {
            MediaPlayer.Stop();
        }
        
        public void PlayShot()
        {
            sShot.Play();
        }

        public void PlayDead()
        {
            sDead.Play();
        }


        public void PlayExplosion()
        {
            sExplosion.Play();
        }

        public void Update()
        {
            if (GameLogic.game_state.Player.Event != null)
            {
                if (GameLogic.game_state.Player.Event.Value.s == "Dead")
                {
                    MediaPlayer.Stop();
                    PlayDead();
                }
                if (GameLogic.game_state.Player.Event.Value.s == "Shot")
                {
                    PlayShot();
                }
            
            }

            
        }
    }
}
